package com.aaa.web.service.emp;

import com.aaa.web.dao.emp.EmpDaoImpl;
import com.aaa.web.dao.emp.Impl.EmpDao;
import com.aaa.web.entity.Emp;
import com.aaa.web.service.emp.Impl.EmpService;

import java.util.List;
import java.util.Map;

/**
 * @ProjectName java_web _demo_20230303_AllServlet
 * @Author 李江波
 * @Date 2023/03/03 上午 09:22
 * @Version 1.0.0
 * @Description
 */
public class EmpServiceImpl implements EmpService {
    private EmpDao empDao = new EmpDaoImpl();

    @Override
    public List<Emp> queryByPage(int pageNo, int pageSize, Emp emp) {
        //计算开始值
        int start = (pageNo-1)*pageSize;
        return empDao.queryByPage(start,pageSize,emp);
    }

    @Override
    public int queryTotal(Emp emp) {
        return empDao.queryTotal(emp);
    }

    @Override
    public List<Emp> queryAll() {
        return empDao.queryAll();
    }

    @Override
    public Emp queryById(int empId) {
        //根据编号查询
        List<Emp> mapList = empDao.queryById(empId);
        //定义emp对象
        if (mapList!=null&&mapList.size()>0){
            for (Emp emp : mapList) {
                return emp;
            }
        }
        return null;
    }

    @Override
    public int add(Emp emp) {
        return empDao.add(emp);
    }

    @Override
    public int update(Emp emp) {
        return empDao.update(emp);
    }

    @Override
    public int deleteById(int empId) {
        return empDao.deleteById(empId);
    }

    @Override
    public Emp queryName(String empName, String password) {
        List<Emp> mapList = empDao.queryName(empName,password);
        if (mapList!=null&&mapList.size()>0){
           return mapList.get(0);
        }else {
            return null;
        }
    }
}
